/**
 * 
 */
package com.org.javabody.ListApi.ListHashMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONArray;

/**
 * @author Administrator
 *
 */

public class ListHashMap {
    /**
     * List+HashMap结合的方法非常好用(List<HashMap<String, Object>>转成JSon,必须是String不能是Integer)
     * @param number 从零开始循环的数值
     * @return
     */
	public static List<HashMap<String, Object>> getList(Integer number) {
		List<HashMap<String, Object>> li = new ArrayList<HashMap<String, Object>>();
		HashMap<String, Object> hash = new HashMap<String, Object>();
		for(int i=0; i<number; i++) {
			hash.put(i+"", i);
			li.add(hash);
		}
		return li;
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 List<HashMap<String, Object>> list = getList(10);
		 System.out.println(list); //输出List

         System.out.println(JSONArray.fromObject(list).toString()); //JSon输出List

         
         List<HashMap<String, Object>> list2 =JSONArray.toList(JSONArray.fromObject(list));
         for(int i=0;i<list2.size();i++){
             System.out.println(list2.get(i));
             }
         
         for(int i=0; i < list.size(); i++) {
        	 HashMap<String, Object> dto = list.get(i);
        	 System.out.print(dto.get("1")); //输出List里面的某个值

        	// System.out.println(dto.get(15)); //输出List里面的某个值，没有返回null
         }
	}
}
